﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataWorks_Tools.SpikeDetails
{
    /// <summary>
    /// 毛刺处理的所有辅助方法工具类
    /// </summary>
    public static class SpikeTools
    {
        /// <summary>
        /// 根据行号获取文件索引
        /// </summary>
        /// <param name="row"></param>
        /// <param name="csvsrowcount"></param>
        /// <returns></returns>
        public static int GetFileIndex(int row, List<int> csvsrowcount)
        {
            int cumulativeRows = 0;
            for (int i = 0; i < csvsrowcount.Count; i++)
            {
                cumulativeRows += csvsrowcount[i];
                if (row < cumulativeRows)
                {
                    return i;
                }
            }
            return -1; // 如果找不到，返回 -1
        }

        /// <summary>
        /// 获取每个文件的起始行号（是在合并后的行数里的起始行号）
        /// </summary>
        /// <param name="fileIndex"></param>
        /// <param name="csvsrowcount"></param>
        /// <returns></returns>
        public static int GetFileStartRow(int fileIndex, List<int> csvsrowcount)
        {
            int startRow = 0;
            for (int i = 0; i < fileIndex; i++)
            {
                startRow += csvsrowcount[i];
            }
            return startRow;
        }
    }
}
